package com.xwq.xwqaiagent.controller;

import com.xwq.xwqaiagent.app.LoveApp.LoveAppWithMul;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;
import reactor.core.publisher.Flux;
import java.util.List;

@RequiredArgsConstructor
@RestController
@RequestMapping("/ai")
public class ChatController {

    private final LoveAppWithMul loveAppWithMul;

    @RequestMapping(value = "/chat", produces = "text/html;charset=utf-8")
    public Flux<String> chat(
            @RequestParam("prompt") String prompt,
            @RequestParam("chatId") String chatId,
            @RequestParam(value = "files", required = false) List<MultipartFile> files) {
        // 2.请求模型
        if (files == null || files.isEmpty()) {
            // 没有附件，纯文本聊天
            return loveAppWithMul.doChat(prompt,chatId);
        } else {
            // 有附件，多模态聊天
            return loveAppWithMul.doChatWithMul(prompt, chatId, files);
        }

    }
}